package com.example.quartztest.service;

import com.example.quartztest.Job.HelloJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @Author: zhaojie
 * @Date: Created in 13:57 2018/5/8
 * @Description:
 * @Modified By:
 */
public class quazrtDemo {
    /**
    *@escription: 定时任务发短信
    */
    public void sendMgs(){
        SchedulerFactory factory=new StdSchedulerFactory();
        Scheduler scheduler=null;
        try {
            scheduler=factory.getScheduler();
            //创建job示例
            JobDetail job=JobBuilder.newJob(HelloJob.class).withIdentity("jobName", "JobGroupName").build();
            //定义触发规则
            Trigger trigger = TriggerBuilder.newTrigger().withIdentity("CronTrigger1", "CronTriggerGroup")
                    .withSchedule(CronScheduleBuilder.cronSchedule("*/1 * * * * ?"))
                    .startNow().build();
            //放入到容器
            scheduler.scheduleJob(job, trigger);
            //启动任务调度
            System.out.println("开始");
            scheduler.start();
            Thread.sleep(10000);
            scheduler.shutdown();
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
